package com.yanqu.road.server.cmd.activity.pixiu;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PiXiuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.pixiu.PiXiuModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.pixiu.PiXiuActivityMgr;
import com.yanqu.road.server.manger.activity.pixiu.PiXiuConfig;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_PI_XIU_GET_ALL_REWARD, desc = "领取返利奖励")
public class PiXiuGetAllRewardCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        // 没有活动
        PiXiuConfig config = PiXiuActivityMgr.getConfig();
        if (config == null || !ActivityMgr.activityInRewardPeriod(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_IN_GET_REWARD_TIME;
            return;
        }

        ret = player.getModule(PiXiuModule.class).getAllReward();
    }

    @Override
    public void sendData(GamePlayer player) {

        if(ret != 0) {
            player.sendPacket(Protocol.U_PI_XIU_GET_ALL_REWARD, PiXiuProto.PiXiuGetAllRewardRespMsg.newBuilder().setRet(ret));
        }

    }
}
